首页

欢迎

 

Welcome

欢迎来到这里, 这是一个学习数学、讨论数学的网站.

转到问题

请输入问题号, 例如: 2512

IMAGINE, THINK, and DO
How to be a scientist, mathematician and an engineer, all in one?
--- S. Muthu Muthukrishnan

Local Notes

Local Notes 是一款 Windows 下的笔记系统.

Local Notes 下载

Sowya

Sowya 是一款运行于 Windows 下的计算软件.

详情

下载 Sowya.7z (包含最新版的 Sowya.exe and SowyaApp.exe)


注: 自 v0.550 开始, Calculator 更名为 Sowya. [Sowya] 是吴语中数学的发音, 可在 cn.bing.com/translator 中输入 Sowya, 听其英语发音或法语发音.





注册

欢迎注册, 您的参与将会促进数学交流. 注册

在注册之前, 或许您想先试用一下. 测试帐号: usertest 密码: usertest. 请不要更改密码.


我制作的 slides

Problem

随机显示问题

Problèmes d'affichage aléatoires

软件 >> Calculator >> Bug
Questions in category: Bug (Bug).

[Bug] 计算 $\sin(\cos(1))$ 的值

Posted by haifeng on 2025-06-08 21:12:02 last update 2025-06-10 10:58:07 | Answers (0)


>> :mode clox
> print sin(cos(1));
0.85755321584639341575>

 

但真实的值为

\[\sin(\cos(1))\approx 0.5143952585\]

 

这里计算的结果0.85755321584639341575 实际上是cos(cos(1))的值. 怀疑是 cos(1) 压入栈后 cos 又压入一次.

在 v0.634 中已经修复.

 

不过 Linux 版本出现了错误:

>> :mode clox
> print sin(cos(1));
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 4294967284) > this->size() (which is 1)
Aborted (core dumped)

后来仔细检查了一下, 问题出在 BigNumber.cpp 中的pre_multiplication()函数. 其中有一行

long long pt_pos = multiplication_rs.length() - point_pos;

特别地, 当 multiplication_rs.length() - point_pos 形如 1-13 时, 原本 pt_pos=-12, 但是在32位程序中, 会得到 pt_pos=4294967284, 这在后面的 substr(pt_pos) 语句执行时会出现 out_of_range()的错误. 注意 4294967284+12=4294967296=2^32

问题解决也很简单, 为避免 pt_pos 出现负数, 索性分情况处理. 如下:

LL pt_pos = 0;
int flag = 1;
if (multiplication_rs.length() >= point_pos)
{
pt_pos = multiplication_rs.length() - point_pos;
flag = 1;
}
else
{
pt_pos = point_pos- multiplication_rs.length();
flag = 0;
}
 
 
 

解决日期: 2025-06-10